unit U_Cons_CausaAssistencia;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls, dbtables, db;

type
  TFCons_CausaAssistencia = class(TFrmConsulta)
    Label1: TLabel;
    edtDescricao: TEdit;
    DbgGrid: TDBGrid;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure edtDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    CausaAss_Codigo: string;
    procedure FazConsulta;
  end;

var
  FCons_CausaAssistencia: TFCons_CausaAssistencia;

implementation

uses clsCausa_Assistencia, biblio, dm;
var
  Causa_Assistencia: TCausa_Assistencia;
  tq: TQuery;
  tds: TDataSource;

{$R *.DFM}

procedure TFCons_CausaAssistencia.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Causa_Assistencia.free;
end;

procedure TFCons_CausaAssistencia.FormCreate(Sender: TObject);
begin
  inherited;
  Causa_Assistencia := TCausa_Assistencia.create;
end;

procedure TFCons_CausaAssistencia.FormActivate(Sender: TObject);
begin
  inherited;
  tds := TDataSource.create(FCons_CausaAssistencia);
  tq := Tquery.create(FCons_CausaAssistencia);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  edtdescricao.setfocus;
end;

procedure TFCons_CausaAssistencia.FazConsulta;
begin
  if edtDescricao.text = '' then
    edtDescricao.text := ' ';
  Causa_Assistencia.Consultar(tq, edtDescricao.text);
  tq.open;
  DbgGrid.DataSource := tds;
  DbgGrid.Refresh;
end;

procedure TFCons_CausaAssistencia.BtnFecharClick(Sender: TObject);
begin
  inherited;
  CausaAss_Codigo := tq.fieldbyname('CausaAss_Codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TFCons_CausaAssistencia.edtDescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    edtdescricao.setfocus;
  end;
end;

end.
